package socket;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author DBX
 * @effect
 * @date 2021/8/30 0030 - 20:13
 */
public class Client1 {
    private Socket socket;
    public Client1() {
        try {
            System.out.println("正在连接服务端。。。");
            socket = new Socket("176.225.131.228",8098);
            System.out.println("连接成功");
        } catch (IOException e) {
            System.out.println("----->");
            e.printStackTrace();
        }

    }
    PrintWriter pw;
    public void start(){
        try {
            pw = new PrintWriter(new BufferedWriter
                    (new OutputStreamWriter
                            (socket.getOutputStream(),"UTF-8")),true);
            Scanner sc = new Scanner(System.in);
            while (true){
                String str = sc.nextLine();
                if ("exit".equals(str)) {
                    break;
                }else {
                    pw.println(str);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (pw != null) {
                pw.close();
            }
        }
    }

    public static void main(String[] args) {
        Client1 client1 = new Client1();
        client1.start();
    }
}
